package sz.szsmk.citizencard.dialog;

import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.RadioButton;
import android.widget.RadioGroup;

import sz.szsmk.citizencard.R;

/**
 * Created by yangzhengwen on 2017/11/22.
 */

public class ChooseCardDialog extends BaseDialog {

    private Context context;
    RadioButton rb_old_card;
    RadioButton rb_new_card;
    RadioGroup rg_select;

    private String oldBankNo = "";
    private String newBankNo = "";

    private int tradeType = -1;

    public interface OnBindCardCheckListener {
        void onBindCheck(int type);
    }

    private OnBindCardCheckListener onBindCardCheckListener;

    public void setOnBindCardCheckListener(OnBindCardCheckListener listener) {
        onBindCardCheckListener = listener;
    }

    public ChooseCardDialog(Context context) {
        super(context);
        this.context = context;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.qr_dialog_choose_card);

        rb_old_card = findViewById(R.id.rb_old_card);
        rb_new_card = findViewById(R.id.rb_new_card);
        rg_select = findViewById(R.id.rg_select);

        findViewById(R.id.ok).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (tradeType != -1) {
                    onBindCardCheckListener.onBindCheck(tradeType);
                    dismiss();
                }
            }
        });


        setCancelable(false);
        setCanceledOnTouchOutside(false);

        rb_old_card.setText(String.format(context.getString(R.string.qr_old_bank_no), oldBankNo));
        rb_new_card.setText(String.format(context.getString(R.string.qr_new_bank_no), newBankNo));

        rg_select.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                if (R.id.rb_old_card == checkedId) {
                    tradeType = 0;
                } else if (R.id.rb_new_card == checkedId) {
                    tradeType = 1;
                }
            }
        });
    }



//    @OnCheckedChanged({R2.id.rb_old_card, R2.id.rb_new_card})
//    public void onCheckChangedView(CompoundButton c) {
//        if (R.id.rb_old_card == c.getId()) {
//            cardNo = oldBankNo;
//            Log.i("123yzw123", cardNo);
//            return;
//        } else if (R.id.rb_new_card == c.getId()) {
//            cardNo = newBankNo;
//            Log.i("123yzw456", cardNo);
//            return;
//        }
//    }

    public String getOldBankNo() {
        return oldBankNo;
    }

    public void setOldBankNo(String oldBankNo) {
        this.oldBankNo = oldBankNo;
    }

    public String getNewBankNo() {
        return newBankNo;
    }

    public void setNewBankNo(String newBankNo) {
        this.newBankNo = newBankNo;
    }
}
